package Level02;

import java.util.*;

public class One {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        TreeMap<String, String> student = new TreeMap<>();
        while (student.size() < 5) {
            System.out.println("请输入学生的信息(”学号,姓名,年龄”): ");
            try {
                String student01 = scanner.nextLine();
                String[] split01 = student01.split(",");
                String name = split01[1];
                String age = split01[2];
                String id = split01[0];
                if (split01.length != 3) {
                    System.out.println("输入有误");
                }else if (student.containsKey(id)){
                    System.out.println("已经有这个id的学生了");
                } else {
                    student.put(id,"名字为："+name+"年龄为："+age);
                    System.out.println("输入成功");
                    if (student.size() == 5) {
                        System.out.println("已经录入5名学生");
                        System.out.println("学生信息如下: "+student);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("输入有误");
            }
        }
    }
}
